using System;
using System.Collections.Generic;
namespace AppToolKit.Data.NHibernate
{
	public class HSqlQuery : TextQuery, IEquatable<HSqlQuery>
	{
		public HSqlQuery(string sql) : base(sql)
		{
		}
		public HSqlQuery(HSqlQuery other) : base(other.sb_.ToString())
		{
		}
		public static HSqlQuery Format(string format, params object[] args)
		{
			HSqlQuery hSqlQuery = new HSqlQuery();
			hSqlQuery.AppendFormat(format, args);
			return hSqlQuery;
		}
		public static HSqlQuery Format(string format, IDictionary<string, object> dict)
		{
			HSqlQuery hSqlQuery = new HSqlQuery();
			hSqlQuery.AppendFormat(format, dict);
			return hSqlQuery;
		}
		public HSqlQuery()
		{
		}
		public static implicit operator string(HSqlQuery right)
		{
			return right.GetValidSql();
		}
		private string GetValidSql()
		{
			return this.sb_.ToString();
		}
		public static implicit operator HSqlQuery(string right)
		{
			return new HSqlQuery(right);
		}
		public override string ToString()
		{
			return this.GetValidSql();
		}
		public override int GetHashCode()
		{
			return (this.sb_ != null) ? this.sb_.GetHashCode() : 0;
		}
		public static bool operator ==(HSqlQuery left, HSqlQuery right)
		{
			return object.Equals(left, right);
		}
		public static bool operator !=(HSqlQuery left, HSqlQuery right)
		{
			return !object.Equals(left, right);
		}
		public bool Equals(HSqlQuery other)
		{
			return !object.ReferenceEquals(null, other);
		}
		public override bool Equals(object obj)
		{
			return !object.ReferenceEquals(null, obj) && (object.ReferenceEquals(this, obj) || (obj.GetType() == typeof(HSqlQuery) && this.Equals((HSqlQuery)obj)));
		}
		protected override string ProcessArgs(object arg)
		{
			if (arg is string)
			{
				 
				string result;
				if (arg is DateTime || (arg is DateTime? && ((DateTime?)arg).HasValue))
				{
					if (arg is DateTime)
					{
						result = ((DateTime)arg).ToString("s");
						return result;
					}
					if (arg is DateTime?)
					{
						result = ((DateTime?)arg).Value.ToString("s");
						return result;
					}
				}
				result = arg.ToString();
				return result;
			}
            return string.Empty;
		}
	}
}
